package com.dongdong.zhuangji.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dongdong.zhuangji.entity.ControlPoints;
import com.dongdong.zhuangji.mapper.ControlPointsMapper;
import com.dongdong.zhuangji.service.ControlPointsService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

@Service
public class ControlPointsServiceImpl extends ServiceImpl<ControlPointsMapper, ControlPoints> implements ControlPointsService {

    @Override
    public Page<ControlPoints> pageQuery(Page<ControlPoints> page, ControlPoints controlPoints) {
       LambdaQueryWrapper <ControlPoints> queryWrapper = new LambdaQueryWrapper<>();
       if(controlPoints!=null){

           Integer id = controlPoints.getId();
           if (id!= null) {
               queryWrapper.eq(id>0, ControlPoints::getId, controlPoints.getId());

           }
           // 如果点名模糊查询条件不为空，则添加模糊查询条件
            queryWrapper.like(Strings.isNotEmpty(controlPoints.getPointName()) , ControlPoints::getPointName, controlPoints.getPointName());
           queryWrapper.like(Strings.isNotEmpty(controlPoints.getDescription()), ControlPoints::getDescription, controlPoints.getDescription());
       }
        // 执行分页查询
        return baseMapper.selectPage(page, queryWrapper);
    }/*
    @Override
    public Page<ControlPoints> pageQuery(Page<ControlPoints> page, ControlPoints controlPoints) {
        QueryWrapper<ControlPoints> queryWrapper = new QueryWrapper<>();
        // 如果点名模糊查询条件不为空，则添加模糊查询条件
        if (controlPoints.getPointNameLike() != null && !"".equals(controlPoints.getPointNameLike())) {
            queryWrapper.like("PointName", controlPoints.getPointNameLike());
        }
        // 执行分页查询
        return baseMapper.selectPage(page, queryWrapper);
    }*/
}